package day37;
import java.util.*;

public class Test {
    public static void main(String[] args) {
        char[] s = {'0','1','2','A'};
        //String[] str = Permutation(s,3);
        System.out.println();
    }

    List<String> ret = new ArrayList<>();
    public String[] Permutation (char[] seed, int size) {
        // write code here
        for(int i=0;i<seed.length;i++) {
            StringBuilder path = new StringBuilder();
            path.append(seed[i]);
            Map<Character,Integer> map = new HashMap<>();
            map.put(seed[i],0);
            dfs(seed,size,map,path);
        }
        Set<String> set = new HashSet<>();
        String[] str = new String[ret.size()];
        for(int i=0;i<ret.size();i++) {
            str[i] = ret.get(i);
        }
        Arrays.sort(str);
        return str;
    }
    public void dfs(char[] seed,int size,Map<Character,Integer> map,StringBuilder path) {
        if(path.length()>=size) {
            ret.add(path.toString());
            return;
        }
        for(int i=0;i<seed.length;i++) {
            if(map.containsKey(seed[i])) continue;
            //1.添加字符
            path.append(seed[i]);
            map.put(seed[i],0);
            dfs(seed,size,map,path);
            //2.回溯
            path.deleteCharAt(path.length()-1);
            map.remove(seed[i]);
        }
    }
}
